import Vue from 'vue'
import Router from 'vue-router'
import store from '../store'

Vue.use(Router)
/* Layout */
import Layout from '@/layout'
//所有权限通用路由表
//如首页和登录页和一些不用权限的公用页面
export const constantRoutes = [
  {
    path: '/login',
    component: () =>
      import ('@/views/login/index'),
    name: 'login'
  },
  {
    path: '/',
    name: 'firstPage',
    component: Layout
  }
]
//管理员
export const asyncAdminRoutes = [
  {
    path: '/adminPage',
    name: 'baseInfo',
    component: Layout,
    redirect: '/adminPage/home',
    meta: { title: '基础信息', icon: 'sheji' },
    children: [ //路径未配置
      {
        path: '/adminPage/home/user',
        name: 'user',
        component: () =>
          import ('@/views/admin/home/user.vue'),
        meta: { title: '用户' }
      },
      {
        path: '/adminPage/home/role',
        name: 'role',
        component: () =>
          import ('@/views/admin/home/role.vue'),
        meta: { title: '角色' }
      },
      {
        path: '/adminPage/home/menu',
        name: 'menu',
        component: () =>
          import ('@/views/admin/home/menu.vue'),
        meta: { title: '菜单' }
      },
      {
        path: '/adminPage/home/styleInfo',
        name: 'styleInfo',
        component: () =>
          import ('@/views/admin/home/styleInfo.vue'),
        meta: { title: '风格配置' }
      },
      {
        path: '/adminPage/home/systemInfo',
        name: 'systemInfo',
        component: () =>
          import ('@/views/admin/home/systemInfo.vue'),
        meta: { title: '应用系统设置' }
      }
    ]
  },
  { //路径未配置
    path: '/adminPage',
    name: 'baseManage',
    component: Layout,
    redirect: '/adminPage/home',
    meta: { title: '配置管理', icon: 'sheji' },
    children: [
      {
        path: '/adminPage/baseInfo',
        name: 'baseInfo',
        component: () =>
          import ('@/views/admin/baseInfo/infoManage.vue'),
        meta: { title: '应用系统设置' }
      }
    ]
  },
  {
    path: '/adminPage',
    name: 'flowManage',
    component: Layout,
    redirect: '/adminPage/home',
    meta: { title: '流程管理', icon: 'sheji' },
    children: [ //路径未配置
      {
        path: '/adminPage/flowManage/dataEmpower',
        name: 'user',
        component: () =>
          import ('@/views/admin/flowInfo/dataEmpower.vue'),
        meta: { title: '数据授权' },
      },
      {
        path: '/adminPage/flowManage/flowEmpower',
        name: 'role',
        component: () =>
          import ('@/views/admin/flowInfo/flowEmpower.vue'),
        meta: { title: '流程授权' },
      }
    ]
  },
  {
    path: '/adminPage',
    name: 'dingDingManage',
    component: Layout,
    redirect: '/adminPage/home',
    meta: { title: '钉钉配置', icon: 'sheji' },
    children: [ //路径未配置
      {
        path: '/adminPage/ding/together',
        name: 'user',
        component: () =>
          import ('@/views/admin/dingDingManage/together.vue'),
        meta: { title: '钉钉集成' },
      },
      {
        path: '/adminPage/ding/infomation',
        name: 'role',
        component: () =>
          import ('@/views/admin/dingDingManage/infomation.vue'),
        meta: { title: '消息模板' },
      }
    ]
  }
]


//实例化vue的时候只挂载constantRouter
const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
